var roleE8S57_R_I = {
    run: function(creep) {

        //creep.say(creep.memory.building);

        if(creep.store.getUsedCapacity()==0){
            creep.memory.building = true;
        }
        if(creep.store.getFreeCapacity()==0){
            creep.memory.building = false;
        }


        if(creep.memory.building == true){
            if(creep.room.name != 'E8S57'){
                //creep.say(321);
                creep.moveTo(Game.flags['E8S57'].pos, {reusePath:20});
            }
            else{
                //creep.say(321321);
                var sources = creep.room.find(FIND_SOURCES);
                if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(sources[0], {reusePath:10});
                }
            }
        }
        else{    
                var targetsfix = creep.room.find(FIND_STRUCTURES, {
                    filter: (structure) => structure.hits < structure.hitsMax*0.8
                });
                targetsfix.sort((a,b) => a.hits - b.hits);
                if(targetsfix.length > 0 && creep.room.name != 'E9S58') {
                    if(creep.repair(targetsfix[0]) == ERR_NOT_IN_RANGE) {
                        creep.moveTo(targetsfix[0] ,{reusePath:10});
                        //creep.say('修去');
                    }
                }
                
            
        }
	}
};

module.exports = roleE8S57_R_I;